// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  // const {nickName,avatarUrl,gender,city,province} = event
  // return await db.collection('user')
  // .where({
  //   nickName
  // }).count()
  // .then(res=>{
  //   if (res.total>0) {
  //     return{
  //       code: 200,
  //       errMsg: "用户已经存在"
  //     }
  //   }else{
      return await db.collection('user')
      .add({
        data: {
          nickName: event.nickName,
          avatarUrl: event.avatarUrl,
          gender: event.gender,
          city: event.city,
          province: event.province,
          intro: "",
          ups: 0,
          focus: 0,
          fans: 0,
          focusId: [],
          upId: []
        }
      })
    }
//   })
// }